<?php
/*
 * This file is part of the BooXtore Student project.
 *
 * (c) Francis Backeland f.backeland@gmail.com
 * (c) Laurine Chaplot chaplot.laurine@orange.fr
 * (c) Julien Dutot julien.dutot@gmail.com
 * (c) Romain Guillaume romain-guillaume@orange.fr
 * (c) Guillaume Paringaux g.paringaux@gmail.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code
 * 
 */
namespace BXTR\BookBundle\Entity;

use Doctrine\ORM\EntityRepository;
use BXTR\AdminBundle\Entity\AdministrableRepository;

/**
 * Class BookCategoryRepository
 */
class BookCategoryRepository extends EntityRepository
{
    public function findAllJoinedToBooksWithoutCategory($category) {
        $em = $this->getEntityManager();
        return $em->createQuery('SELECT c, b FROM BXTRBookBundle:BookCategory c LEFT JOIN c.books b WHERE c != :category')
            ->setParameter('category', $category)
            ->getResult();
    }

    public function findOneByIdJoinedToBooks($id) {
        $em = $this->getEntityManager();
        return $em->createQuery('SELECT c, b FROM BXTRBookBundle:BookCategory c LEFT JOIN c.books b WHERE c = :categoryId')
            ->setParameter('categoryId', $id)
            ->getSingleResult();
    }

    public function findAllJoinedToBooks() {
        $em = $this->getEntityManager();
        return $em->createQuery('SELECT c, b FROM BXTRBookBundle:BookCategory c LEFT JOIN c.books b')
            ->getResult();
    }
}
